
/**
 * 页面刷新
 * @param [query] url后追加的参数
 * @param [url=window.location.href] 要跳转页面的地址，默认当前页面
 * @example refresh(query);
 */
export default function refresh(query?: any, url = window.location.href) {
	if (query) {

		const usp = new URLSearchParams();
		for (const k in query) {
			if (query.hasOwnProperty(k)) {
				usp.append(k, query[k]);
			}
		}
		const url_param = usp.toString();
		const _url = url.split('?')[0] + (url_param && url_param.length !== 0 ? '?' + url_param : '');
		window.location.assign(_url);
		// window.location.assign(generate(query, url));	// with histry
	} else {
		window.location.reload();
	}
}
